package com.dmap.analysispoint.service.impl;

import com.dmap.analysispoint.service.GetCompanyIdService;
import com.dmap.analysispoint.service.SelectAllCompanyIdByProjectIdService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * \* @author:zhouhao
 * \* Date:04/07/2018
 * \* Description:
 * \*
 */
@Service
public class SelectAllCompanyIdByProjectIdServiceImpl implements SelectAllCompanyIdByProjectIdService {

    @Resource
    private GetCompanyIdService getCompanyIdService;

    @Override
    public List<Long> selectCompanyIdByProjectId(List<String> projectIdList) {
        if (CollectionUtils.isEmpty(projectIdList)) {
            return Collections.emptyList();
        }
        Set<Long> companyIdSet = new HashSet<>();
        for (String projectId : projectIdList) {
            long companyId = getCompanyIdService.getCompanyIdByProjectId(projectId);
            companyIdSet.add(companyId);
        }
        return new ArrayList<>(companyIdSet);
    }
}
